﻿@{
    ViewBag.Title = "AccountEdit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@{
    var action = ViewData["action"].ToString();
    string Id = ViewData["Id"].ToString();
    string width = ViewData["width"].ToString();
    string role = ViewData["role"].ToString();
} 

<div class="mod_dialog" style="display: block; margin-top: @width; left: 0px">
    <form id="frmAccount" class="layui-form" lay-filter="frmAccount">
        <div class="hd">
            @{if (action == "add")
            {
                <h3>添加账号</h3>
            }
            else
            {<h3>修改账号</h3>}
            }
        </div>
        <div class="bd">
            <div class="form clearfix nouse" data-col="0">

                <ul class="form clearfix">
                    <li>
                        <label class="label">账号：</label>
                        <div class="inptxt">
                            <p></p>
                            @{if (action == "add")
                            {
                                <input type="text" name="USERNAME" lay-filter="USERNAME" lay-verify="required" autocomplete="off" class="layui-input">
                            }
                            else
                            {
                                <input type="text" name="USERNAME" lay-filter="USERNAME" lay-verify="required" autocomplete="off" disabled="disabled" class="layui-input">
                            }
                            }
                        </div>

                    </li>
                    <li>
                        <label class="label">类型：</label>
                        <div class="inptxt" style="width:200px">
                            <p></p>
                            @{if (role == "用户")
                            {
                                <select name="ROLE" lay-filter="ROLE" class="layui-inline">
                                    <option value="用户">用户</option>
                                </select>
                            }
                            else if (role == "超级管理员")
                            {
                                <select name="ROLE" lay-filter="ROLE" class="layui-inline">
                                    <option value="超级管理员">超级管理员</option>
                                </select>
                            }
                            else
                            {
                                <select name="ROLE" lay-filter="ROLE" class="layui-inline">
                                    <option value="管理员">管理员</option>
                                    <option value="用户">用户</option>
                                </select>
                            }
                            }
        </div>
    </li>
    @{if (action == "add")
    {
        <li>
            <label class="label">初始密码：</label>
            <div class="inptxt">
                <p></p>
                <input type="text" name="PASSWORD" lay-filter="PASSWORD" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </li>
    }
    }
    <li>
        <label class="label">姓名：</label>
        <div class="inptxt">
            <p></p>
            <input type="text" name="NAME" lay-filter="NAME" lay-verify="required" autocomplete="off" class="layui-input">
        </div>

    </li>
    <li>
        <label class="label">手机：</label>
        <div class="inptxt">
            <p></p>
            @{if (role == "用户")
            {
                <input type="text" name="PHONE" lay-filter="PHONE" autocomplete="off" disabled="disabled" class="layui-input">
            }
            else
            {
                <input type="text" name="PHONE" lay-filter="PHONE" autocomplete="off" class="layui-input">
            }
            }
        </div>

    </li>
    @*<li>
        <label class="label">生效日期：</label>
        <div class="inptxt">
            <p></p>
            <input type="text" id="txtCREATED_TIME" name="CREATED_TIME" lay-filter="CREATED_TIME" lay-verify="required" autocomplete="off" class="layui-input" placeholder="yyyy-MM-dd">
        </div>

    </li>*@
                    <li>
                        <label class="label">登陆方式：</label>
                        <div class="inptxt" style="width:200px">
                            <p></p>
                            <select name="USER_TYPE" lay-filter="USER_TYPE" class="layui-inline">
                                <option value="0">Web</option>
                                <option value="1">App</option>
                                <option value="2">Web&App</option>
                            </select>
                        </div>
                    </li>
                    <li>
                        <label class="label">是否激活：</label>
                        <div class="inptxt" style="width:200px">
                            <p></p>
                            <select name="IS_ACTIVE" lay-filter="IS_ACTIVE" class="layui-inline">
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                        </div>
                    </li>
                </ul>
            </div>
            </div>
        <div class="fd">
                    <div class="load_btn">
                        @{if (action == "add")
                        {
                            <button class="btn_green_m" id="btnAdd" lay-submit="" lay-filter="btnAdd">保存添加</button>
                            <button class="btn_gray_m" id="btnCancel" >取消添加</button>
                        }
                        else
                        {<button class="btn_green_m" id="btnEdit" lay-submit="" lay-filter="btnEdit">保存修改</button>
    <button class="btn_gray_m" id="btnCancel" style="height:33px;width:145px">取消修改</button>
                        }}
                    </div>
                </div>
    </form>
</div>
<script type="text/javascript">
    $(function () {
        if ("@action" == "edit") {
            $.ajax({
                url: "/Setting/GetAccountByUserId/@Id",
                type: "post",
                dataType: "json",
                success: function (data) {
                    var form = layui.form;
                    form.val("frmAccount", data);
                    form.render(); //刷新select选择框渲染
                }
            });
        }
        var form = layui.form;
        form.render(); //刷新select选择框渲染

        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //常规用法
            laydate.render({
                elem: '#txtCREATED_TIME'
            });
        });

        form.on('submit(btnAdd)', function (data) {
            var account = $.extend(data.field, { USER_ID: "@Id" });
            com.ajax({
                url: "/Setting/AddAccount", type: "post", dataType: "json", data: account, success: function (data) {
                    parent.$("#infoList").datagrid("load");
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }
            });
            return false;
        });

        form.on('submit(btnEdit)', function (data) {
            var account = $.extend(data.field, { USER_ID: "@Id" });
            com.ajax({
                url: "/Setting/EditAccount", type: "post", dataType: "json", data: account, success: function (data) {
                    parent.$("#infoList").datagrid("load");
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }
            });
            return false;
        });
    });


    $("#btnCancel").click(function () {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
        return false;
    });

    @*$("#btnAdd").click(function () {
        var account = com.serializeObj("frmAccount");
        com.ajax({
            url: "/Setting/AddAccount", type: "post", dataType: "json", data: account, success: function (data) {
                parent.$("#infoList").datagrid("load");
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            }
        });
        return false;
    });


    $("#btnEdit").click(function () {
        var account = com.serializeObj("frmAccount");
        account.USER_ID = "@Id";
        com.ajax({
            url: "/Setting/EditAccount", data: account, type: "post", dataType: "json", success: function (data) {
                parent.$("#infoList").datagrid("load");
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            }
        });
        return false;
    });*@

</script>